package com.cyl.XmlDemo.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Service;

import com.cyl.XmlDemo.entity.DMsg;

@Service
public class MsgServiceImpl implements MsgService {
	
	private static final Logger logger = LoggerFactory.getLogger(MsgServiceImpl.class);
	
	private static final String COMMON_CHANNEL = "/topic/common/message";
	private static final String PRIVATE_CHANNEL = "/topic/private/message";
	
	@Autowired
	private SimpMessagingTemplate messaging;

	@Override
	public void sendToUser(DMsg dmsg) {
		messaging.convertAndSendToUser(dmsg.getTarget(), PRIVATE_CHANNEL, dmsg);
	}

	@Override
	public void sendToChannel(Object obj) {
		
	}
	
	public void transferMsg(DMsg dmsg){
		messaging.convertAndSendToUser(dmsg.getTarget(), dmsg.getDest(), dmsg);
	}
	
	public void transferTalkMsg(DMsg dmsg){
		messaging.convertAndSendToUser(dmsg.getSender(), PRIVATE_CHANNEL, dmsg);
		messaging.convertAndSendToUser(dmsg.getTarget(), PRIVATE_CHANNEL, dmsg);
	}

}
